package classpath

import (
	"os"
	"strings"
)

// 系统分隔符，直接用api获取，与系统相关，不同系统不一样（windos为';' 类unix为':'）
const pathListSeparator = string(os.PathListSeparator)

// Entry 类路径
type Entry interface {
	// readClass 负责寻找、读取class文件
	readClass(className string) ([]byte, Entry, error)
	// String 返回变量的字符串解释
	String() string
}

func newEntry(path string) Entry {
	//分隔多路径类文件
	if strings.Contains(path, pathListSeparator) {
		return newCompositeEntry(path)
	}
	//通配符
	if strings.HasSuffix(path, "*") {
		return newWildcardEntry(path)
	}
	//jar或zip
	if strings.HasSuffix(path, ".jar") ||
		strings.HasSuffix(path, ".zip") ||
		strings.HasSuffix(path, ".JAR") ||
		strings.HasSuffix(path, ".ZIP") {
		return newZipEntry(path)
	}
	//目录
	return newDirEntry(path)
}
